package web.gkw.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import web.gkw.model.User;
import web.gkw.service.UserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Component
public class UserAction extends ActionSupport {

	@Resource(name="userService")
	private UserService service;

	public UserService getService() {
		return service;
	}
	public void setService(UserService service) {
		this.service = service;
	}

	private Map session; 
	private User user;

	public Map getSession() {
		return session;
	}
	public void setSession(Map session) {
		this.session = session;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		System.out.println(session == null);
		ActionContext ctx2 =ActionContext.getContext();
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try {
			out = response.getWriter();
			session = ctx2.getSession();
			if(session!= null) {
				System.out.println(session.containsKey("user"));
				if(session.containsKey("user")) {
					session.remove("user");
					System.out.println("user has been remove from session...");
					out.println(true);
				}else {
					out.println(false);
				}
			}else {
				out.println(false);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "success";

	}
	

}
